package spacegame;

public class Main {

    public static Map mapFromArray (int xsize, int ysize, 
				    Artifact[] art, int min, int max) {
	if (min==max)
	    return Map.artifact(xsize,ysize,art[min]);
	return Map.merge(mapFromArray(xsize,ysize,art,min,(max-min)/2+min),
			 mapFromArray(xsize,ysize,art,(max-min)/2+min+1,max));
    }
    
    public static void main (String[] argv) {
	
	Artifact[] art = new Artifact[5];
	
	art[0] = Artifact.planet(Coord.create(20,8),"Euphor");
	art[1] = Artifact.ship(Coord.create(10,1),"Arcadia",50);
	art[2] = Artifact.star(Coord.create(14,5),"Rao");
	art[3] = Artifact.base(Coord.create(25,3),"Babylon 5",100);
	art[4] = Artifact.star(Coord.create(0,0),"Sol");
	
	Map m = mapFromArray(30,10,art,0,4);
	
	MapLib.displayArtifacts(m);

	System.out.println("\nInitial state:");
	MapLib.drawMap(m);

	Artifact arcadia = m.findArtifactByName("Arcadia").valOf();
	Map m1 = MapLib.moveArtifact(m,arcadia,4,4);
	MapLib.drawMap(m1);

	arcadia = m1.findArtifactByName("Arcadia").valOf();
	Map m2 = MapLib.moveArtifact(m1,arcadia,3,3);
	MapLib.drawMap(m2);

	arcadia = m2.findArtifactByName("Arcadia").valOf();
	Map m3 = MapLib.fireAtArtifact(m2,arcadia,1,1);
	MapLib.drawMap(m3);

	arcadia = m3.findArtifactByName("Arcadia").valOf();
	Map m4 = MapLib.fireAtArtifact(m3,arcadia,2,2);
	MapLib.drawMap(m4);

	Map result = m4;
	for (int i=0; i<11; i++) {
	    arcadia = result.findArtifactByName("Arcadia").valOf();
	    result = MapLib.fireAtArtifact(result,arcadia,12,-1);
	}
	MapLib.drawMap(result);

    }

}